package com.itheima.hmshopping.app.config;


import com.itheima.hmshopping.entity.UmsAdmin;
import org.springframework.context.annotation.Configuration;

/**
 * 工具类：实现向threadlocal存储数据的方法
 */
@Configuration
public class UserHolder {

    private static ThreadLocal<UmsAdmin> tl = new ThreadLocal<>();


    //将用户对象，存入Threadlocal
    public static void set(UmsAdmin user) {
        tl.set(user);
    }

    //从当前线程，获取用户对象
    public static UmsAdmin get() {
        return tl.get();
    }

    //从当前线程，获取用户对象的id
    public static Long getUserId() {
        return tl.get().getId();
    }

}